package org.wmq.shopmanager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wmq.commonutil.result.Result;
import org.wmq.shopmanager.service.BrandService;
import org.wmq.shopmodel.Entity.product.Brand;

import java.util.List;

@RestController
@RequestMapping("/admin/product/brand")
@RequiredArgsConstructor
public class BrandController {
    private final BrandService brandService;

    @GetMapping("/page/{pageNo}/{pageSize}")
    public Result<IPage<Brand>> getBrandPageItem(@PathVariable Long pageNo,@PathVariable Long pageSize){
        return Result.success(this.brandService.page(new Page<>(pageNo,pageSize)));
    }

    @PostMapping
    public Result<Void> saveBrand(@RequestBody Brand brand){
        this.brandService.save(brand);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result<Void> removeBrandById(@PathVariable Long id){
        this.brandService.removeById(id);
        return Result.success();
    }

    @GetMapping("/getAll")
    public Result<List<Brand>> getAllBrands(){
        return Result.success(this.brandService.list());
    }
}
